<?php
/* 	These code was generated using phpCIGen v 0.1.b (21/04/2009)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com, 
	
	+ Module  		: m_staff Controller
	+ Description	: For record controller process back-end
	+ Filename 		: C_m_staff.php
 	+ creator 		: 
 	+ Created on 06/Mar/2012 12:35:49
	
*/

//class of m_staff
class C_m_staff extends CI_Controller {

	//constructor
	function C_m_staff(){
		parent::__construct();
		session_start();
		$this->load->model('m_m_staff', '', TRUE);
	}
	
	//set index
	function index(){
		$this->load->view('main/v_m_staff');
	}
	
	//event handler action
	function get_action(){
		$task = $_POST['task'];
		switch($task){
			case "LIST":
				$this->m_staff_list();
				break;
			case "UPDATE":
				$this->m_staff_update();
				break;
			case "CREATE":
				$this->m_staff_create();
				break;
			case "DELETE":
				$this->m_staff_delete();
				break;
			case "SEARCH":
				$this->m_staff_search();
				break;
			case "PRINT":
				$this->m_staff_print();
				break;
			case "EXCEL":
				$this->m_staff_export_excel();
				break;
			default:
				echo "{failure:true}";
				break;
		}
	}
	
	//function fot list record
	function m_staff_list(){
		
		$query = isset($_POST['query']) ? @$_POST['query'] : "";
		$start = (integer) (isset($_POST['start']) ? @$_POST['start'] : @$_GET['start']);
		$end = (integer) (isset($_POST['limit']) ? @$_POST['limit'] : @$_GET['limit']);
		$result=$this->m_m_staff->m_staff_list($query,$start,$end);
		echo $result;
	}
	
	//function for create new record
	function m_staff_create(){
		//POST varible here
		//auto increment, don't accept anything from form values
		$staff_name=trim(@$_POST["staff_name"]);
		$staff_name=htmlentities($staff_name,ENT_QUOTES);
		$staff_address=trim(@$_POST["staff_address"]);
		$staff_address=htmlentities($staff_address,ENT_QUOTES);
		$staff_city=trim(@$_POST["staff_city"]);
		$staff_city=htmlentities($staff_city,ENT_QUOTES);
		$staff_hp=trim(@$_POST["staff_hp"]);
		$staff_hp=htmlentities($staff_hp,ENT_QUOTES);
		$staff_email=trim(@$_POST["staff_email"]);
		$staff_email=htmlentities($staff_email,ENT_QUOTES);
		$result=$this->m_m_staff->m_staff_create($staff_name ,$staff_address ,$staff_city ,$staff_hp ,$staff_email );
		echo $result;
	}
	
	
	//function for update record
	function m_staff_update(){
		//POST variable here
		$staff_id=@$_POST["staff_id"];
		$staff_id=is_numeric($staff_id)?$staff_id:0;
		$staff_name=trim(@$_POST["staff_name"]);
		$staff_name=htmlentities($staff_name,ENT_QUOTES);
		$staff_address=trim(@$_POST["staff_address"]);
		$staff_address=htmlentities($staff_address,ENT_QUOTES);
		$staff_city=trim(@$_POST["staff_city"]);
		$staff_city=htmlentities($staff_city,ENT_QUOTES);
		$staff_hp=trim(@$_POST["staff_hp"]);
		$staff_hp=htmlentities($staff_hp,ENT_QUOTES);
		$staff_email=trim(@$_POST["staff_email"]);
		$staff_email=htmlentities($staff_email,ENT_QUOTES);
		$result = $this->m_m_staff->m_staff_update($staff_id,$staff_name,$staff_address,$staff_city,$staff_hp,$staff_email);
		echo $result;
	}
	
	//function for delete selected record
	function m_staff_delete(){
		$ids = @$_POST['ids']; // Get our array back and translate it :
		$pkid = json_decode(stripslashes($ids));
		$result=$this->m_m_staff->m_staff_delete($pkid);
		echo $result;
	}

	//function for advanced search
	function m_staff_search(){
		//POST varibale here
		$staff_id=@$_POST["staff_id"];
		$staff_id=is_numeric($staff_id)?$staff_id:0;
		$staff_name=trim(@$_POST["staff_name"]);
		$staff_name=htmlentities($staff_name,ENT_QUOTES);
		$staff_address=trim(@$_POST["staff_address"]);
		$staff_address=htmlentities($staff_address,ENT_QUOTES);
		$staff_city=trim(@$_POST["staff_city"]);
		$staff_city=htmlentities($staff_city,ENT_QUOTES);
		$staff_hp=trim(@$_POST["staff_hp"]);
		$staff_hp=htmlentities($staff_hp,ENT_QUOTES);
		$staff_email=trim(@$_POST["staff_email"]);
		$staff_email=htmlentities($staff_email,ENT_QUOTES);
		
		$start = (integer) (isset($_POST['start']) ? $_POST['start'] : $_GET['start']);
		$end = (integer) (isset($_POST['limit']) ? $_POST['limit'] : $_GET['limit']);
		$result = $this->m_m_staff->m_staff_search($staff_id ,$staff_name ,$staff_address ,$staff_city ,$staff_hp ,$staff_email ,$start,$end);
		echo $result;
	}


	function m_staff_print(){
  		//POST varibale here
		$staff_id=@$_POST["staff_id"];
		$staff_id=is_numeric($staff_id)?$staff_id:0;
		$staff_name=trim(@$_POST["staff_name"]);
		$staff_name=htmlentities($staff_name,ENT_QUOTES);
		$staff_address=trim(@$_POST["staff_address"]);
		$staff_address=htmlentities($staff_address,ENT_QUOTES);
		$staff_city=trim(@$_POST["staff_city"]);
		$staff_city=htmlentities($staff_city,ENT_QUOTES);
		$staff_hp=trim(@$_POST["staff_hp"]);
		$staff_hp=htmlentities($staff_hp,ENT_QUOTES);
		$staff_email=trim(@$_POST["staff_email"]);
		$staff_email=htmlentities($staff_email,ENT_QUOTES);
		$option=$_POST['currentlisting'];
		$filter=$_POST["query"];
		
		$data["data_print"] = $this->m_m_staff->m_staff_print($staff_id ,$staff_name ,$staff_address ,$staff_city ,$staff_hp ,$staff_email ,$option,$filter);
		$print_view=$this->load->view("main/p_m_staff.php",$data,TRUE);
		if(!file_exists("print")){
			mkdir("print");
		}
		$print_file=fopen("print/m_staff_printlist.html","w+");
		fwrite($print_file, $print_view);
		echo '1';        
	}
	/* End Of Function */

	/* Function to Export Excel document */
	function m_staff_export_excel(){
		//POST varibale here
		$staff_id=@$_POST["staff_id"];
		$staff_id=is_numeric($staff_id)?$staff_id:0;
		$staff_name=trim(@$_POST["staff_name"]);
		$staff_name=htmlentities($staff_name,ENT_QUOTES);
		$staff_address=trim(@$_POST["staff_address"]);
		$staff_address=htmlentities($staff_address,ENT_QUOTES);
		$staff_city=trim(@$_POST["staff_city"]);
		$staff_city=htmlentities($staff_city,ENT_QUOTES);
		$staff_hp=trim(@$_POST["staff_hp"]);
		$staff_hp=htmlentities($staff_hp,ENT_QUOTES);
		$staff_email=trim(@$_POST["staff_email"]);
		$staff_email=htmlentities($staff_email,ENT_QUOTES);
		$option=$_POST['currentlisting'];
		$filter=$_POST["query"];
		
		$query = $this->m_m_staff->m_staff_export_excel($staff_id ,$staff_name ,$staff_address ,$staff_city ,$staff_hp ,$staff_email ,$option,$filter);
		
		to_excel($query,"m_staff"); 
		echo '1';
			
	}
	
	// Encodes a SQL array into a JSON formated string
	function JEncode($arr){
		if (version_compare(PHP_VERSION,"5.2","<"))
		{    
			require_once("./JSON.php"); //if php<5.2 need JSON class
			$json = new Services_JSON();//instantiate new json object
			$data=$json->encode($arr);  //encode the data in json format
		} else {
			$data = json_encode($arr);  //encode the data in json format
		}
		return $data;
	}
	
	// Decode a SQL array into a JSON formated string
	function JDecode($arr){
		if (version_compare(PHP_VERSION,"5.2","<"))
		{    
			require_once("./JSON.php"); //if php<5.2 need JSON class
			$json = new Services_JSON();//instantiate new json object
			$data=$json->decode($arr);  //decode the data in json format
		} else {
			$data = json_decode($arr);  //decode the data in json format
		}
		return $data;
	}
	
	
}
?>